# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>
_realname=appdirs
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.4.3
pkgrel=2
pkgdesc='A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir" (mingw-w64)'
arch=('any')
url="https://github.com/ActiveState/appdirs"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools" "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
source=("https://pypi.io/packages/source/a/appdirs/appdirs-$pkgver.tar.gz")
sha256sums=('9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92')

prepare() {  
  cd "$srcdir"/
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}  
  
# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.  
build() {  
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {  
  for pver in {2,3}; do  
    msg "Python ${pver} test for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"  
    ${MINGW_PREFIX}/bin/python${pver} setup.py test
  done  
}

package_python3-appdirs() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/COPYING"
}


package_python2-appdirs() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/python2-build-${CARCH}"

  rm -f ./buildutils/include_win32/stdint.h
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/COPYING"

}

package_mingw-w64-i686-python2-appdirs() {
  package_python2-appdirs
}

package_mingw-w64-i686-python3-appdirs() {
  package_python3-appdirs 
}

package_mingw-w64-x86_64-python2-appdirs() {
  package_python2-appdirs
}

package_mingw-w64-x86_64-python3-appdirs() {
  package_python3-appdirs
}

